package com.wgts.wgts.mvp.presenter.imp;

import com.wgts.wgts.mvp.model.IMainActivityModel;
import com.wgts.wgts.mvp.presenter.IMainActivityPersenter;
import com.wgts.wgts.mvp.view.IMainActivityView;
import com.wgts.wgts.netmodle.HttpResultSubscriber;
import com.wgts.wgts.netmodle.resp.AppUpdateEntity;
import com.wgts.wgts.netmodle.resp.UserInfoEntity;
import com.wgts.wgts.netmodle.resp.VipMessageEntity;
import com.wgts.wgts.tools.AppInfor;

import java.util.List;

/*
 *
 *   data:2018/9/2615:33
 *
 */public class MainActivityPersenter implements IMainActivityPersenter {
     private IMainActivityModel model;
     private IMainActivityView view;

    public MainActivityPersenter(IMainActivityModel model, IMainActivityView view) {
        this.model = model;
        this.view = view;
    }

    @Override
    public void vipMessage() {
        model.vipMessage(new HttpResultSubscriber<List<VipMessageEntity>>() {
            @Override
            public void onSuccess(List<VipMessageEntity> vipMessageEntities) {
                view.vipMessage(vipMessageEntities);
            }

            @Override
            public void _onError(int status, String msg) {
                view.onError(status, msg);
            }
        });
    }

    @Override
    public void userInfo() {

        if(AppInfor.getInstance().getRefreshToken().equals("")){
            view.userInfoResult(null);
            return;
        }

        model.userInfo(new HttpResultSubscriber<UserInfoEntity>() {
            @Override
            public void onSuccess(UserInfoEntity userInfoEntity) {
                AppInfor.getInstance().setUserPhone(userInfoEntity.userPhone);
                AppInfor.getInstance().setUserState(userInfoEntity.userRole);
                AppInfor.getInstance().setAvailableBalance(userInfoEntity.availableBalance);
                AppInfor.getInstance().setUserYQCode(userInfoEntity.userCode);
                AppInfor.getInstance().setInviteCode(userInfoEntity.userCode);
                AppInfor.getInstance().setModifyPayPassword(userInfoEntity.modifyPayPassword);
                view.userInfoResult(userInfoEntity);
            }

            @Override
            public void _onError(int status, String msg) {
                view.onError(0xffff, msg);
            }
        });
    }

    @Override
    public void appUpdate(String channel, String version) {
        model.appUpdate(channel, version, new HttpResultSubscriber<AppUpdateEntity>() {
            @Override
            public void onSuccess(AppUpdateEntity appUpdateEntity) {
                view.appUpdate(appUpdateEntity);
            }

            @Override
            public void _onError(int status, String msg) {
                view.onError(status, msg);
            }
        });
    }


}
